package com.zany.children.dao;

import com.zany.children.vo.Teacher;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 教师信息dao.
 */
public class TeacherDaoImpl extends SqlMapClientDaoSupport implements TeacherDao {


    @Override
    public List<Teacher> getTeacherListPage(Map<String,Object> teacher) {
        List list = getSqlMapClientTemplate().queryForList("teacher.getTeacherListPage", teacher);
        return list;
    }

    @Override
    public Integer getTeacherListPageCount(Map<String,Object> teacher) {
        Integer count = (Integer) getSqlMapClientTemplate().queryForObject("teacher.getTeacherListPageCount", teacher);
        return count;
    }

    @Override
    public Long saveTeacher(Teacher teacher) {
        Long id = (Long) getSqlMapClientTemplate().insert("teacher.insertTeacher", teacher);
        return id;
    }

    @Override
    public void updateTeacher(Teacher teacher) {
        int update = getSqlMapClientTemplate().update("teacher.updateTeacher", teacher);
    }

    @Override
    public Teacher getTeacherById(Long id) {
        Teacher teacher = (Teacher) getSqlMapClientTemplate().queryForObject("teacher.getTeacherById", id);
        return teacher;
    }


    @Override
    public void saveClassTeacherRela(Long classId, Long teaId, String creater) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("classId", classId);
        map.put("teaId", teaId);
        map.put("creater", creater);
        getSqlMapClientTemplate().insert("teacher.saveClassTeacherRela", map);
    }


    @Override
    public void deleteClassTeacherRelaByTeaId(Long teaId){
        getSqlMapClientTemplate().delete("teacher.deleteClassTeacherRelaByTeaId",teaId);
    }


    @Override
    public void deleteTeacherById(Long teaId) {
        getSqlMapClientTemplate().update("teacher.deleteTeacherById", teaId);
    }
}
